package com.zprmb.udzt.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.ExperienceGoldProduct;
import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.ExBean;
import com.zprmb.udzt.util.BitmapUtils;
import com.zprmb.udzt.util.Regular;

public class Ex_adapter extends BaseAdapter {
	private Context context;
	private List<ExBean> list;
	

	public Ex_adapter(Context context, List<ExBean> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("NewApi")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Log.e("getview", "getview");
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.ex_gold_item2, null);
			h.tv_activity=(TextView)convertView.findViewById(R.id.tv_channel);
			h.tv_amount=(TextView)convertView.findViewById(R.id.amount);
			h.tv_date=(TextView)convertView.findViewById(R.id.tv_date);
			h.tv_invest=(TextView)convertView.findViewById(R.id.btn_invest);
			h.tv_term=(TextView)convertView.findViewById(R.id.shouyi_term);
			h.li_bg=(RelativeLayout)convertView.findViewById(R.id.li_bg);
			convertView.setTag(h);
			
		}else{
			h=(Help) convertView.getTag();
		} 
//		h.li_bg.setBackgroundResource(R.drawable.bjj);
		h.li_bg.setBackground(new BitmapDrawable(BitmapUtils.readBitMap(context,R.drawable.bjj)));
		h.tv_activity.setText(list.get(position).getExperienceName());
		h.tv_amount.setText("¥"+list.get(position).getExperienceAmount());
		if(list.get(position).getEndTime()!=null){
			
			h.tv_date.setText("有效期:  "+Regular.getMilliToDate(list.get(position).getStartTime())+"至"+Regular.getMilliToDate(list.get(position).getEndTime()));
		}
		h.tv_invest.setText("立即体验");
		h.tv_term.setText("收益期限: "+list.get(position).getExperienceDays()+"天");
		h.tv_invest.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent =new Intent(context,ExperienceGoldProduct.class);
				intent.putExtra("id", list.get(position).getUserExpId());
				context.startActivity(intent);
				
			}
		});
		return convertView;
		
	}
	class Help{
		private TextView tv_activity,tv_amount,tv_term,tv_invest,tv_date;
		private RelativeLayout li_bg;
		
	}
}
